/* ******** vue 数据绑定 ******** */
var im_vm;


/* ******** 工具类集 ******** */
var tz_utils = {
}


/* ******** 数据处理 ******** */


/* 演示版 存储于storage */
var tz_im = {

	/* ********  数据请求 [此处数据 为模拟数据，请自行ajax向自己服务端 获取数据]  ******** */

	// 临时用 随机返回消息
	"ls_re_msg":function(obj){
		var demo_returnMsg = [
			{"content":"你好呀~","type":0},
			{"content":"tzboy好帅~","type":0},
			{"content":"你认识tzboy吗？  那货帅得一逼~","type":0},
			{"content":"我不是个机器人，我是比机器人(或者nv ren……我什么都没说)还难猜的生物 -- 因为我-随机回答","type":0},
			{"content":"再见！不送~ 记得点赞 关注","type":0},
		];

		var d = demo_returnMsg[Math.floor(Math.random()*demo_returnMsg.length)];
		
		var p = {
			"from":obj.to,
			"from_obj":obj.to_obj,
			"to":obj.from,
			"to_obj":obj.from_obj,
			"date":new Date(),
		};

		var r = Object.assign({},p,d);

		tzImlogs = JSON.parse(sessionStorage.tzImlogs);
		tzImlogs[r['from']].push(r);
		sessionStorage.tzImlogs = JSON.stringify(tzImlogs);
	},

	// 发送消息
	"sendMsg":function(params){
		var def = {
			"from":"",
			"from_obj":{},
			"to":"",
			"to_obj":{},
			"content":"",
			"type":0, // 0纯文本,1图片，2视频【随意 自己定】
			"date":new Date(),
			"success":function(res){}
		};
		var op = Object.assign({},def,params);

		// 这里应向后台传输数据 【此处以H5 SessionStorage 处理为例】
		var tzImlogs = {};
		if(sessionStorage.tzImlogs){
			tzImlogs = JSON.parse(sessionStorage.tzImlogs);
		}

		// 此处简化 直接以聊天对象Key存储【就是作者懒 没毛病】
		tzImlogs[op['to']] = (tzImlogs[op['to']]!=null)?tzImlogs[op['to']]:[];

		let d = op;
		tzImlogs[op['to']].push(d);
		sessionStorage.tzImlogs = JSON.stringify(tzImlogs);

		op['success'](d);
	},

	// 获取聊天记录
	"getImLogs":function(params){
		let def = {
			"params":{"key":""},
			"success":function(res){}
		};
		var op = Object.assign({},def,params);

		if(op['params']==null||op['params']['key']==null||op['params']['key']==""){console.error("【error】获取聊天记录 失败！参数Key 不可为空");}

		let demo_data = [];
		if( sessionStorage.tzImlogs){
			var tzImlogs = JSON.parse(sessionStorage.tzImlogs);
			 demo_data = tzImlogs[op['params']['key']]||[];
		}


		op['success'](demo_data);
	},

	// 登录
	"login":function(params){
		let def = {
			"success":function(res){}
		};
		var op = Object.assign({},def,params);
		
		let demo_data = {"key":"tzboy","name":"tzboy","avatar":"/static/ls/avatar_3.jpg",'signature':'我命由我，不由天！天命如此，我便逆了这天'};

		op['success'](demo_data);
	},

	// 主面板-人员分组数据
	"buildMasterMemberList":function(params){
		let def = {
			"success":function(res){}
		};
		var op = Object.assign({},def,params);

		let demo_data = [
			{
				"group":{"name":"Html","id":"1"},
				"member_list":[
					{'id':"1","name":"React","avatar":"/static/ls/avatar_3.jpg",'signature':'我命由我，不由天！天命如此，我便逆了这天'},
					{'id':"2","name":"Vue","avatar":"/static/ls/avatar_1.jpg",'signature':'尘归尘，土归土'},
				]
			},
			{
				"group":{"name":"PHP","id":"2"},
				"member_list":[
					{'id':"3","name":"Laravel","avatar":"/static/ls/avatar_2.jpg",'signature':'为了部落'},
					{'id':"4","name":"Thinkphp","avatar":"/static/ls/avatar_1.jpg",'signature':'联盟终将灭绝！'},
					{'id':"5","name":"Yii","avatar":"/static/ls/avatar_3.jpg",'signature':'熊猫人永不为奴！'},
				]
			},
			{
				"group":{"name":"Nodejs","id":"3"},
				"member_list":[
					{'id':"6","name":"Express","avatar":"/static/ls/avatar_1.jpg",'signature':'想不出来签名了……'},
					{'id':"7","name":"Sails","avatar":"/static/ls/avatar_2.jpg",'signature':'我好帅……哇哈哇哈哇哈'},
					{'id':"8","name":"KOA","avatar":"/static/ls/avatar_3.jpg",'signature':'我单身，我骄傲'},
				]
			}
		];
		op['success'](demo_data);
	},


	// 主面板-组群数据
	"buildMasterTeamList":function(params){
		let def = {
			"success":function(res){}
		};
		var op = Object.assign({},def,params);

		let demo_data = [
			{"name":"欢乐一家人","avatar":"/static/ls/team_3.jpg","id":"1",'signature':'相亲相爱一家亲'},
			{"name":"幸福大家庭","avatar":"/static/ls/team_1.jpg","id":"2",'signature':'永远永远在一起'},
			{"name":"打野小分队","avatar":"/static/ls/team_2.jpeg","id":"3",'signature':'为了部落'},
		];
		op['success'](demo_data);
	},

	// 主面板-历史数据
	"buildMasterLogsList":function(params){
		let def = {
			"success":function(res){}
		};
		var op = Object.assign({},def,params);

		let demo_data = [
			{"name":"欢乐一家人","avatar":"/static/ls/team_3.jpg","id":"team_1",'signature':'相亲相爱一家亲'},
			{"name":"Laravel","avatar":"/static/ls/avatar_2.jpg",'id':"member_3",'signature':'为了部落'},
			{"name":"Thinkphp","avatar":"/static/ls/avatar_1.jpg",'id':"member_4",'signature':'联盟终将灭绝！'},
			{"name":"打野小分队","avatar":"/static/ls/team_2.jpeg","id":"team_3",'signature':'为了部落'},
		];
		op['success'](demo_data);
	}

	

}